package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.dto.MaterialAccessoriesDto;
import com.sale.common.log.annotation.Log;
import com.sale.system.domain.vo.MaterialAccessoriesVo;
import com.sale.system.service.IMaterialAccessoriesService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Description 辅料信息控制层
 * @Param
 * @Date 22-11-25
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/accessories")
public class MaterialAccessoriesController extends BaseController {

    private final IMaterialAccessoriesService materialAccessoriesService;

    /**
     * 获取辅料配置
     */
    @GetMapping("/list")
    @SaCheckPermission("material:accessories:list")
    public TableDataInfo<MaterialAccessoriesDto> list(MaterialAccessoriesVo materialAccessoriesVo, PageQuery pageQuery)
    {
        return materialAccessoriesService.selectAccessoriesList(materialAccessoriesVo,pageQuery);
    }

    /**
     * 新增辅料信息
     */
    @SaCheckPermission("material:accessories:add")
    @Log(title = "辅料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody MaterialAccessoriesVo materialAccessoriesVo) throws Exception {
        return toAjax(materialAccessoriesService.insertAccessories(materialAccessoriesVo));
    }


    /**
     * 删除辅料信息
     */
    @SaCheckPermission("material:accessories:remove")
    @Log(title = "辅料信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{materialId}")
    public R<Void> remove(@PathVariable("materialId") String materialId) throws Exception {
        return toAjax(materialAccessoriesService.deleteAccessories(materialId));
    }

    /**
     * 根据编号获取详细信息
     */
    @SaCheckPermission("material:accessories:query")
    @GetMapping(value = "/{materialId}")
    public R getAccessoriesInfo(@PathVariable long materialId)
    {
        return R.ok(materialAccessoriesService.selectAccessoriesById(materialId));
    }

    /**
     * 修改辅料信息
     */
    @SaCheckPermission("material:accessories:edit")
    @Log(title = "辅料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody MaterialAccessoriesVo materialAccessoriesVo) throws Exception {
        return toAjax(materialAccessoriesService.updateAccessoriesEdit(materialAccessoriesVo));
    }

    /**
     * 辅料冻结
     */
    //@RequiresPermissions("material:awmateria:editFreeze")
    @Log(title = "辅料信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editFreeze/{materialId}")
    public R editFreeze(@PathVariable Long materialId) {
        return R.ok(materialAccessoriesService.updateEditFreeze(materialId));
    }

    /**
     * 辅料解冻
     */
    // @RequiresPermissions("material:awmateria:editThaw")
    @PutMapping("/editThaw/{materialId}")
    public R editThaw(@PathVariable Long materialId) {
        return R.ok(materialAccessoriesService.updateEditThaw(materialId));
    }


}
